package com.ruoyi.project.platform.service.impl;

import java.util.List;

import com.ruoyi.common.exception.Exceptions;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
import com.ruoyi.framework.security.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.platform.mapper.PltUserApiMapper;
import com.ruoyi.project.platform.domain.PltUserApi;
import com.ruoyi.project.platform.service.IPltUserApiService;

/**
 * 用户apikeyService业务层处理
 * 
 * @author ruoyi
 * @date 2020-07-27
 */
@Service
public class PltUserApiServiceImpl implements IPltUserApiService 
{
    @Autowired
    private PltUserApiMapper pltUserApiMapper;

    /**
     * 查询用户apikey
     * 
     * @param apiId 用户apikeyID
     * @return 用户apikey
     */
    @Override
    public PltUserApi selectPltUserApiById(Long apiId)
    {

//        return pltUserApiMapper.selectPltUserApiById(apiId);
        throw Exceptions.BAD_NOT_SUPPORT_API;
    }

    /**
     * 查询用户apikey列表
     * 
     * @param pltUserApi 用户apikey
     * @return 用户apikey
     */
    @Override
    @DataScope(userAlias = "u")
    public List<PltUserApi> selectPltUserApiList(PltUserApi pltUserApi)
    {
        return pltUserApiMapper.selectPltUserApiList(pltUserApi);
    }

    /**
     * 新增用户apikey
     * 
     * @param pltUserApi 用户apikey
     * @return 结果
     */
    @Override
    public int insertPltUserApi(PltUserApi pltUserApi)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        pltUserApi.setUserId(currentUser.getUser().getUserId());
        pltUserApi.setUserName(currentUser.getUser().getUserName());
        return pltUserApiMapper.insertPltUserApi(pltUserApi);
    }

    /**
     * 修改用户apikey
     * 
     * @param pltUserApi 用户apikey
     * @return 结果
     */
    @Override
    public int updatePltUserApi(PltUserApi pltUserApi)
    {
        return pltUserApiMapper.updatePltUserApi(pltUserApi);
    }

    /**
     * 批量删除用户apikey
     * 
     * @param apiIds 需要删除的用户apikeyID
     * @return 结果
     */
    @Override
    public int deletePltUserApiByIds(Long[] apiIds)
    {
        return pltUserApiMapper.deletePltUserApiByIds(apiIds);
    }

    /**
     * 删除用户apikey信息
     * 
     * @param apiId 用户apikeyID
     * @return 结果
     */
    @Override
    public int deletePltUserApiById(Long apiId)
    {
        return pltUserApiMapper.deletePltUserApiById(apiId);
    }
}
